package com.fc.campusapplicationsystem.service;

import com.fc.campusapplicationsystem.mapper.AreaMapper;
import com.fc.campusapplicationsystem.model.Area;
import com.fc.campusapplicationsystem.model.Asset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 贺哲
 * @2020-02-29 15:13
 */
@Service
public class AreaServiceImpl implements AreaService{
    @Autowired
    AreaMapper areaMapper;

    @Override
    public Integer add(Area area) {
        return areaMapper.insertSelective(area);
    }

    @Override
    public Integer delete(Integer id) {
        return areaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Area> list(String key) {
        List<Area> areaList = new ArrayList<>();
        Example example = new Example(Asset.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isEmpty(key)) {
            areaList = areaMapper.selectAll();
        } else {
            criteria.andLike("areaName", "%" + key + "%");
            areaList = areaMapper.selectByExample(example);
        }
        return areaList;
    }

    @Override
    public Integer update(Area area) {
        return null;
    }
}
